package cn.tedu.v1.mapper;

import cn.tedu.v1.model.DepartmentOffice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * <p>
 * 部门列表 Mapper 接口
 * </p>
 *
 * @author tedu.cn
 * @since 2021-07-06
 */
@Repository
public interface DepartmentOfficeMapper extends BaseMapper<DepartmentOffice> {
    //查询所有诊疗部门
    @Select("select id,name,status,chairman,office_name,department_id,office_id from department_office where " +
            "department_id=1")
    List<DepartmentOffice> selectDepartmentOfficeList();
    @Select("select id,name,status,chairman,office_name,department_id,office_id from department_office WHERE " +
            " department_id IN (1,2,3) ")
    List<DepartmentOffice> medicalDepartmentOfficeList();

    @Update("update department_office set delete_status = 1 where id = #{id}")
    Integer updateDeleteStatusById(Integer id);

    @Select("SELECT COUNT(a.id) FROM department_office c LEFT JOIN doctors a ON c.office_id = a.office_id WHERE c.department_id = #{id}")
    Integer getDepartmentPeopleQuantity(Integer id);

    @Select("SELECT distinct department_id FROM department_office")
    Integer[] getDepartmentQuantity();

    @Select("SELECT distinct name FROM department_office")
    String[] getDepartmentName();

    @Select("SELECT distinct department_id FROM department_office WHERE name = #{name}")
    Integer selectDepartmentIdByDepartmentName(String name);

    @Select("select max(department_id) from department_office")
    Integer selectDepartmentIdMax();

    @Select("select max(office_id) from department_office")
    Integer selectOfficeIdMax();

    @Select("select distinct name from department_office where department_id = #{id}")
    String selectNameById(Integer id);
}
